package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.contract.SupplyContract;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

public class stockMsgHandler implements MsgHandler {
    @Autowired
    private VendingMachineService machineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        //将接受到的JSON转换为SupplyContract对象，这里使用的是JSON工具
        SupplyContract contract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
        //更新库存
        machineService.updateInventory(contract);
    }
}
